﻿using System.Drawing;
using System.Windows.Forms;
using Infrastructure;

namespace SubsDownloader
{
    public partial class Main : Form
    {

        public Main ()
        {
            InitializeComponent();
        }

        private void SaveState ()
        {
            var formSettings = SettingsManager.Instane.GetSettings<FormSettings>();
            formSettings.MainFormLocation = Location;
            formSettings.MainFormSize = Size;
            formSettings.MainFormState = WindowState;
            SettingsManager.Instane.SaveSettings();
        }

        private void RestoreState ()
        {
            bool success;
            var formSettings = SettingsManager.Instane.GetSettings<FormSettings>( out success );
            if (success)
            {
                Location = formSettings.MainFormLocation;
                Size = formSettings.MainFormSize;
                WindowState = formSettings.MainFormState;
            }
            else
            {
                formSettings.MainFormLocation = Location;
                formSettings.MainFormSize = Size;
                formSettings.MainFormState = WindowState;
            }
        }

        private void Main_Load ( object sender, System.EventArgs e )
        {
            RestoreState();
        }

        private void Main_FormClosing ( object sender, FormClosingEventArgs e )
        {
            SaveState();
        }
    }
}
